import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsArray, IsEnum, IsInt, IsOptional, IsString } from 'class-validator';
import { ArticleContentType } from './article-content.entity';
import { PagerDto } from '~/common/dto/pager.dto';

export class CreateArticleContentDto {
	// code
	@ApiProperty({ description: '编码', default: '' })
	@IsString()
	@IsOptional()
	code: string;

  @ApiProperty({ description: '租户ID', default: 1 })
  @IsOptional()
  tenantId: number;

  @ApiProperty({ description: '分类ID', default: [] })
  @IsOptional()
  categorieIds: number[];

  @ApiProperty({ description: '文章名称', default: '' })
  @IsString()
  name: string;

  @ApiProperty({ description: '文章banner', default: null })
  @IsString()
	@IsOptional()
  banner: string;

  @ApiProperty({ description: '文章作者', default: '' })
  @IsString()
  author: string;

  @ApiProperty({ description: '文章内容', default: '' })
  @IsString()
  content: string;

	@ApiProperty({ description: '文章html内容', default: '' })
	@IsString()
	@IsOptional()
	rawHtml: string;

	@ApiProperty({ description: '文章发布时间', default: '' })
	@IsString()
	@IsOptional()
	publishTime: string;

	@ApiProperty({ description: '文章文件名称', default: '' })
	@IsString()
	@IsOptional()
	fileName: string;

	@ApiProperty({ description: '文章类型', default: '' })
	@IsEnum(ArticleContentType)
	@IsOptional()
	type: ArticleContentType;
}

export class ArticleBindCategoryDto {
	@ApiProperty({ description: '分类ID', type: [Number], default: [] })
	@IsArray()
  @Type(() => Number)
	categorieIds: number[];

	@ApiProperty({ description: '文章ID', default: '' })
	@IsInt()
	articleId: number;
}

export class UpdateArticleRawHtmlDto {
	@ApiProperty({ description: '文章ID', default: 1 })
	@IsInt()
	id: number;

	@ApiProperty({ description: '文章HTML内容', default: '' })
	@IsString()
	rawHtml: string;
}

export class SimpleCreateArticleContentDto {
	@ApiProperty({ description: '编码', required: true })
	@IsString()
	code: string;

	@ApiProperty({ description: '分类ID', required: true })
	@IsInt()
	categoryId: number;

	@ApiProperty({ description: '文章名称', required: false })
	@IsString()
	@IsOptional()
	name?: string;

	@ApiProperty({ description: '文章HTML内容', required: true })
	@IsString()
	rawHtml: string;

	@ApiProperty({ description: '视频链接（多链接逗号分隔）', required: false })
	@IsString()
	@IsOptional()
	video?: string;

	@ApiProperty({ description: '文章banner', required: false })
	@IsString()
	@IsOptional()
	banner?: string;

	@ApiProperty({ description: '文章作者', required: false })
	@IsString()
	@IsOptional()
	author?: string;

	@ApiProperty({ description: '文章类型', required: false })
	@IsString()
	@IsOptional()
	type?: string;
}

export class SimpleUpdateArticleContentDto {
	@ApiProperty({ description: '编码', required: false })
	@IsString()
	@IsOptional()
	code?: string;

	@ApiProperty({ description: '文章名称', required: false })
	@IsString()
	@IsOptional()
	name?: string;

	@ApiProperty({ description: '文章HTML内容', required: false })
	@IsString()
	@IsOptional()
	rawHtml?: string;

	@ApiProperty({ description: '视频链接（多链接逗号分隔）', required: false })
	@IsString()
	@IsOptional()
	video?: string;

	@ApiProperty({ description: '文章banner', required: false })
	@IsString()
	@IsOptional()
	banner?: string;

	@ApiProperty({ description: '文章作者', required: false })
	@IsString()
	@IsOptional()
	author?: string;
}

export class ScienceKnowledgePageDto extends PagerDto {
	@ApiProperty({ description: '分类ID', required: false })
	@IsInt()
	@IsOptional()
	@Type(() => Number)
	categoryId?: number;

	@ApiProperty({ description: '文章名称（模糊查询）', required: false })
	@IsString()
	@IsOptional()
	name?: string;

	@ApiProperty({ description: '编码（模糊查询）', required: false })
	@IsString()
	@IsOptional()
	code?: string;
}
